package com.vegetable.config;

import lombok.Data;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 企业微信配置类
 *
 * @author <a href="https://github.com/binarywang">Binary Wang</a>
 */
@Data
@Configuration
public class WxCPConfig {
    @Value("${wechat.cp.corpId}")
    private String corpId;
    @Value("${wechat.cp.appConfig.secret}")
    private String corpSecret;
    @Value("${wechat.cp.appConfig.agentId}")
    private Integer agentId;

    @Bean
    public WxCpService wxCpService(){
        WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
        config.setCorpId(corpId);
        config.setCorpSecret(corpSecret);
        config.setAgentId(agentId);
        WxCpService cpService = new WxCpServiceImpl();
        cpService.setWxCpConfigStorage(config);
        return cpService;
    }

}